home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / misc / xconf1.c < prev    next >
C/C++ Source or Header  |  1996-06-15  |  5KB  |  165 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "../dialog/dialog.h"
  5. #include "misc.h"
  6. #include "misc.m"
  7.  
  8. /*
  9.     pop up a menu in the center of the screen.
  10.     Return MENU_ESCAPE, MENU_QUIT, MENU_OK, MENU_DEL or MENU_INS
  11. */
  12. MENU_STATUS xconf_menu_gen (
  13.     const char *title,    // Window's title
  14.     const char *explan,    // Explanation of the selection to do
  15.     HELP_FILE &helpfile,    // Help file or help_nil
  16.     int options,        // MENUBUT_...
  17.     const char *opt[],    // Option list ending with NULL
  18.                         // Each option is a pair. (Keyword, description)
  19.                         // opt[0] is keyword, opt[1] is description
  20.                         // opt[2] is nex tkeyword, etc...
  21.     int &choice)        // Will contain de selection in the menu
  22. {
  23.     int err = 0;
  24.     for (int nbopt=0; opt[nbopt] != NULL; nbopt++){
  25.         nbopt++;
  26.         if (opt[nbopt] == NULL){
  27.             fprintf (stderr,"xconf_menu, bad opt[]\n");
  28.             err = 1;
  29.             break;
  30.         }
  31.     }
  32.     // This strange addition is there to illustrate how
  33.     // dialog_menu creates its window. The 2s show the border
  34.     nbopt /= 2;
  35.     MENU_STATUS ret = MENU_ESCAPE;
  36.     if (err == 0){
  37.         dialog_clear();
  38.         ret = dialog_menu (title,explan
  39.             ,helpfile.getpath()
  40.             ,options
  41.             ,nbopt,(char**)opt,choice);
  42.     }
  43.     return ret;
  44. }
  45.  
  46. /*
  47.     pop up a menu in the center of the screen.
  48.     Return MENU_ESCAPE, MENU_QUIT, MENU_OK
  49. */
  50. MENU_STATUS xconf_menu (
  51.     const char *title,    // Window's title
  52.     const char *explan,    // Explanation of the selection to do
  53.     HELP_FILE &helpfile,    // Help file or help_nil
  54.     const char *opt[],    // Option list ending with NULL
  55.                         // Each option is a paire. (Keyword, description)
  56.                         // opt[0] is keyword, opt[1] is description
  57.                         // opt[2] is nex tkeyword, etc...
  58.     int &choice)        // Will contain de selection in the menu
  59. {
  60.     return xconf_menu_gen (title,explan,helpfile,0,opt,choice);
  61. }
  62. /*
  63.     pop up a menu in the center of the screen.
  64.     Return MENU_ESCAPE, MENU_QUIT, MENU_OK
  65. */
  66. MENU_STATUS xconf_menu (
  67.     const char *title,    // Window's title
  68.     const char *explan,    // Explanation of the selection to do
  69.     const char *opt[],    // Option list ending with NULL
  70.                         // Each option is a paire. (Keyword, description)
  71.                         // opt[0] is keyword, opt[1] is description
  72.                         // opt[2] is nex tkeyword, etc...
  73.     int &choice)        // Will contain de selection in the menu
  74. {
  75.     return xconf_menu (title,explan,help_nil,opt,choice);
  76. }
  77. /*
  78.     pop up a menu in the center of the screen with help and save option.
  79.     Return MENU_ESCAPE, MENU_QUIT, MENU_OK, MENU_SAVE, MENU_DEL or MENU_INS
  80.  
  81.     Manage the help itself.
  82. */
  83. MENU_STATUS xconf_menu (
  84.     const char *title,    // Window's title
  85.     const char *explan,    // Explanation of the selection to do
  86.     HELP_FILE &helpfile,    // Help file or help_nil
  87.     const char *save_what,    // Tell what the SAVE button will save or NULL
  88.     const char *ins_what,    // Tell what the INS button will do or NULL
  89.                             // if it is not allowed
  90.     const char *del_what,    // Tell what the DEL button will do or NULL
  91.                             // if it is not allowed
  92.     const char *add_what,    // Tell what the ADD button do or NULL
  93.                             // if it is not allowed
  94.     const char *opt[],    // Option list ending with NULL
  95.                         // Each option is a paire. (Keyword, description)
  96.                         // opt[0] is keyword, opt[1] is description
  97.                         // opt[2] is nex tkeyword, etc...
  98.     int &choice)        // Will contain de selection in the menu
  99. {
  100.     char *tmp_explan = (char*)malloc(strlen(explan)+2000);
  101.     strcpy (tmp_explan,explan);
  102.     int options = 0;
  103.     if (save_what != NULL){
  104.         strcat (tmp_explan,"\n");
  105.         strcat (tmp_explan,"Select <Save> ");
  106.         strcat (tmp_explan,save_what);
  107.         options |= MENUBUT_SAVE;
  108.     }
  109.     if (add_what != NULL){
  110.         strcat (tmp_explan,"\n");
  111.         strcat (tmp_explan,"Select <Add > ");
  112.         strcat (tmp_explan,add_what);
  113.         options |= MENUBUT_ADD;
  114.     }
  115.     if (ins_what != NULL){
  116.         strcat (tmp_explan,"\n");
  117.         strcat (tmp_explan,"Select <Ins > ");
  118.         strcat (tmp_explan,ins_what);
  119.         options |= MENUBUT_INS;
  120.     }
  121.     if (del_what != NULL){
  122.         strcat (tmp_explan,"\n");
  123.         strcat (tmp_explan,"Select <Del > ");
  124.         strcat (tmp_explan,del_what);
  125.         options |= MENUBUT_DEL;
  126.     }
  127.     return  xconf_menu_gen (title,tmp_explan,helpfile,options
  128.             ,opt,choice);
  129. }
  130.  
  131. /*
  132.     Ask a question and return MENU_YES if the user answer yes.
  133.     may Return MENU_NO or MENU_ESCAPE also
  134. */
  135. MENU_STATUS xconf_yesno(
  136.     const char *title,
  137.     const char *prompt,
  138.     HELP_FILE &helpfile)    // Help file or help_nil
  139. {
  140.     dialog_clear();
  141.     return dialog_yesno(title,prompt,helpfile.getpath());
  142. }
  143.  
  144.  
  145. /*
  146.     Return != 0 if the user accept to quit anyway.
  147. */
  148. int xconf_quitwosave()
  149. {
  150.     return xconf_yesno(MSG_U(T_QUIT,"Quit without saving ?")
  151.         ,MSG_U(I_QUIT,"You have modified the information somewhat\n"
  152.          "Are you sure you want to quit ?\n")
  153.         ,help_nil)==MENU_YES;
  154. }
  155. /*
  156.     Return != 0 if the user confirm something.
  157. */
  158. int xconf_areyousure(const char *msg)
  159. {
  160.     return xconf_yesno(MSG_U(T_AREYOUSURE,"Are you sure ?")
  161.         ,msg
  162.         ,help_nil)==MENU_YES;
  163. }
  164.  
  165.